package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.server.service.UserService;
import com.tanhua.server.service.VoiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 用户详情控制器
 */
@RestController
@RequestMapping("/users")
@Slf4j
public class UserInfoController {

    @Autowired
    private UserService userService;

    @Autowired
    private VoiceService voiceService;

    /**
     * 用户资料 - 读取
     * 接口路径：GET/users
     */
    @GetMapping
    public ResponseEntity<Object> findUserInfoById() {
        log.info("用户资料 - 读取");
        return userService.findUserInfoById();
    }

    /**
     * 用户资料 - 保存
     * 接口路径：PUT/users
     */
    @PutMapping
    public ResponseEntity<Object> updateUserInfo(@RequestBody UserInfo userInfo) {

        log.info("用户资料 - 保存");
        return userService.updateUserInfo(userInfo);
    }

    /**
     * 互相喜欢，喜欢，粉丝 - 统计
     * 接口路径：GET/users/counts
     */
    @GetMapping("counts")
    public ResponseEntity<Object> queryCounts() {

        log.info("互相喜欢，喜欢，粉丝 - 统计");
        return userService.queryCounts();
    }

    /**
     * 互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表
     * 接口路径：GET/users/friends/:type
     */
    @GetMapping("friends/{type}")
    public ResponseEntity<Object> queryUserLikeList(@PathVariable Integer type,
                                                    @RequestParam(defaultValue = "1") Integer page,
                                                    @RequestParam(defaultValue = "10") Integer pagesize) {

        log.info("互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表");
        return userService.queryUserLikeList(type, page, pagesize);
    }

    /**
     * 粉丝 - 喜欢
     * 接口路径：POST/users/fans/:uid
     */
    @PostMapping("fans/{uid}")
    public ResponseEntity<Object> fansLike(@PathVariable Long uid) {

        log.info("粉丝 - 喜欢");
        return userService.fansLike(uid);
    }

    //    /**
//     * 是否喜欢（新增接口）
//     * 接口路径：GET/users/:uid/alreadyLove
//     */
//    @GetMapping("{uid}/alreadyLove")//uid这里是随机获取到语音作者id
//    public ResponseEntity<Object> alreadyLove(@PathVariable Long uid){
//
//        return voiceService.alreadyLove(uid);
//    }
//    @PostMapping("fans/{uid}")
//    public ResponseEntity<Object> alreadyLove(@PathVariable Long uid) {
//
//        log.info("粉丝 - 喜欢");
//        return voiceService.alreadyLove(uid);
//    }
}
